package com.micro.modual.extension;

import com.micro.common.MicroConstant;
import com.micro.common.biz.GeneratorCodeUtil;
import com.micro.common.util.SnowFlakeUtil;
import com.micro.modual.entity.Seckill;
import com.micro.modual.entity.SeckillActivitySence;
import com.micro.modual.model.bo.seckill.SeckillBO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <h1>秒杀表 延展类</h1>
 *
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:23:26
 */
public class SeckillExtension {

    /**
     * <h2>转换: 秒杀表 新增</h2>
     *
     * @param seckillBO {@link SeckillBO} 秒杀表 新增/修改 请求对象
     * @return {@link Seckill} 秒杀表
     */
    public static Seckill converAddSeckill(SeckillBO seckillBO,String seckillCode) {
        Seckill seckill = new Seckill();
        seckill.setId(SnowFlakeUtil.getId());
        seckill.setSeckillName(seckillBO.getSeckillName());
        seckill.setSeckillCode(GeneratorCodeUtil.generatorSystemCode());
        seckill.setOnlineStatus(seckillBO.getOnlineStatus());
        seckill.setSeckillStatus(MicroConstant.StatusEffective.ENABLE);
        seckill.setStartDate(seckillBO.getStartDate());
        seckill.setEndDate(seckillBO.getEndDate());
        seckill.setCreateTime(new Date());
        return seckill;
    }

    /**
     * <h2>转换秒杀活动时间关联信息</h2>
     * @param seckillCode     秒杀活动编号
     * @param sceneCodeList   秒杀时间编号列表
     * @return
     */
    public static List<SeckillActivitySence> convertAddSeckillActivitySence(String seckillCode, List<String> sceneCodeList) {
        List<SeckillActivitySence> seckillActivitySenceList = new ArrayList<>();
        for(String sceneCode:sceneCodeList){
            SeckillActivitySence seckillActivitySence = new SeckillActivitySence();
            seckillActivitySence.setId(SnowFlakeUtil.getId());
            seckillActivitySence.setSeckillCode(seckillCode);
            seckillActivitySence.setSceneCode(sceneCode);
            seckillActivitySence.setGoodsCount(MicroConstant.SystemDefaultValue.DEFAULT_START_COUNT);
            seckillActivitySenceList.add(seckillActivitySence);
        }
        return seckillActivitySenceList;
    }

    /**
     * <h2>转换: 秒杀表 修改</h2>
     *
     * @param seckillBO {@link SeckillBO} 秒杀表 新增/修改 请求对象
     * @return {@link Seckill} 秒杀表
     */
    public static Seckill converEditSeckill(SeckillBO seckillBO) {
        Seckill seckill = new Seckill();
        seckill.setId(seckillBO.getId());
        seckill.setSeckillName(seckillBO.getSeckillName());
        seckill.setOnlineStatus(seckillBO.getOnlineStatus());
        seckill.setStartDate(seckillBO.getStartDate());
        seckill.setEndDate(seckillBO.getEndDate());
        seckill.setUpdateTime(new Date());
        return seckill;
    }
}
